<?php

function tf_create_zip_fille() {
  $zip = new zipfile();

  foreach ($_POST['ziparray'] as $file_name) {
    if (strpos($file_name, 'images/') !== FALSE) {
      $filename = THFRPATH . 'uploads/' . str_replace('images/', '', $file_name);
      $fsize = @filesize($filename);
      $fh = fopen($filename, 'rb');
      $file_content = fread($fh, $fsize);
      fclose($fh);
    } else {
      $thisTemplate = str_replace('.php', '', $file_name);
      if ($file_name == 'style.css') {
        $file_content = tf_print_css_code(0);
      } elseif ($file_name == 'javascript.js') {
        $file_content = tf_print_js();
      } elseif ($file_name == 'functions.php') {
        $file_content = tf_create_functions_file();
      } elseif ($file_name == 'header.php') {
        $file_content = tf_create_header_file();
      } elseif ($file_name == 'footer.php') {
        $file_content = tf_create_footer_file();
      } elseif ($file_name == 'loop.php') {
        $file_content = tf_create_loop_file();
      } else {
        $file_content = tf_create_php_file($thisTemplate);
      }
    }
    $zip->addFile($file_content, $file_name);
  }
  $zipcontents = $zip->file();
  header("Content-type: application/octet-stream");
  header("Content-Disposition: attachment; filename=\"TheZip.zip\"");
  header("Content-length: " . strlen($zipcontents) . "\n\n");
  // output data
  echo $zipcontents;
}

?>